<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>

  <fmt:setBundle basename="ApplicationMessage" />
  <fmt:setLocale value="zh_CN" />

  <%@ include file="/WEB-INF/include/meta.jsp"%>
  <%@ include file="/WEB-INF/include/css.jsp"%>
  <link href="${ctx.resource}/css/select2.css" rel="stylesheet">
  <link href="${ctx.resource}/css/select2-bootstrap.css" rel="stylesheet">
  <title>待付列表 - 租房宝金融管理平台</title>
  
</head>
<body>

  <%@ include file="/WEB-INF/include/header.jsp"%>
  
  <div class="web-g-main">

    <%@ include file="/WEB-INF/include/aside.jsp"%>
    <div class="content">
      <header class="header clearfix">
          <h3 class="pull-left">代收付待付列表</h3>
       </header>

       <c:if test="${not empty infoMessage}">
            <div class="alert alert-success alert-dismissable alert-fade top-margin-10 text-align-center">
              <button type="button" class="close" data-dismiss="alert">&times;</button>
              <i class="glyphicon glyphicon-info-sign"></i>&nbsp;&nbsp;
              <fmt:message key="${infoMessage}" />
            </div>
       </c:if>

       <ul class="nav nav-tabs color-tabs">
         <li><a href="${ctx}/payment/waiting/factoring" class="settlement-tab">保理待付</a></li>
         <li class="active"><a href="javascript:void(0)" class="unsettlement-tab" >非保理待付</a></li>
         <li><a href="${ctx}/payment/manage/apply" class="settlement-tab">付款申请</a></li>
         <li><a href="${ctx}/payment/manage/success" class="settlement-tab">付款成功</a></li>
       </ul>

       <div class="table-area">
          <div class="btn-toolbar pull-left">
			<div class="row">
				<form method="GET" action="${ctx}/payment/waiting/agency/search">
				<div class="col-xs-4">

					<div class="input-group pull-left">
						<span class="input-group-addon" id="basic-addon1">商户</span> 
						<select class="form-control" name="app" id="app">
							<option value=""/>
                           <c:forEach var="app" items="${appList }">
                             <option value="${app.id }" <c:if test="${app.id eq appId }">selected</c:if>>${app.name }</option>
                           </c:forEach>
                        </select>   
					</div>

				</div>

				<div class="col-xs-2">
					<div class="btn-group pull-right">
						<button
							class="btn btn-default btn-shadow btn-shadow-default demo2do-btn">
							<i class="glyphicon glyphicon-search"></i>&nbsp;&nbsp;查询
						</button>
					</div>
				</div>

		      </form> 
			</div>
          </div>         
           <table class="data-list">
              <thead>
                <tr>
                  <th style="max-width:65px;"><div class="checkbox"><label><input type="checkbox" id="checkall">全选</label></div></th>
                  <th>订单号</th>
                  <th>付款人</th>
                  <th>收款银行</th>
                  <th>收款账户名</th>
                  <th>收款账号</th>
                  <th>订单金额</th>
                  <th>订单状态</th>
                  <!-- <th>操作</th> -->
                </tr>
              </thead>
              <tbody>
                <c:forEach var="paymentInfo" items="${paymentInfoList}">
                  <tr>
                    <td>
						<input type="checkbox" name="checkbox" value="${paymentInfo.order.id }"/>
                    </td>
                    <td>${paymentInfo.order.orderNo}</td>
                    <td>${paymentInfo.order.customer.name}</td>
                    <td>${paymentInfo.receiveAccount.bank.fullName }</td>
                    <td>${paymentInfo.receiveAccount.accountName }</td>
                    <td>${paymentInfo.receiveAccount.accountNo }</td>
                    <td>&yen;&nbsp;${paymentInfo.order.totalRent}</td>
                    <td><fmt:message key="${paymentInfo.order.orderStatus.key}" /></td>
                    <%-- <td>
                      <a href="${ctx}/payment/${order.id}/payouting" data-target="#" data-toggle="modal">打款</a>&nbsp;&nbsp;
                    </td> --%>
                  </tr>
                </c:forEach>
              </tbody>
           </table>
           
            <%-- <c:choose>
              <c:when test="${not empty queryString}">
                <jsp:include page="/WEB-INF/include/page.jsp">
                  <jsp:param name="url" value="payment/waiting/search" />
                  <jsp:param name="queryString" value="${queryString}" />
                </jsp:include>
              </c:when>
              <c:otherwise>
                <jsp:include page="/WEB-INF/include/page.jsp">
                  <jsp:param value="payment/waiting" name="url" />
                </jsp:include>
              </c:otherwise>
            </c:choose> --%> 
			&nbsp;
          <div class="btn-toolbar pull-right">
			<div class="row">
					<div class="col-xs-4">

						<div class="input-group pull-right">
							<span class="input-group-addon" id="basic-addon1">打款备注</span> <input
								type="text" class="form-control" id="remark" aria-describedby="basic-addon1">
						</div>

					</div>

				<div class="col-xs-2">
					<div class="btn-group pull-right">
						<button
							class="btn btn-default btn-shadow btn-shadow-default demo2do-btn" id="applyBtn">&nbsp;&nbsp;申请付款
						</button>
					</div>
				</div>

			</div>
          </div>  		
       <br/>
       <%-- <%@ include file="/WEB-INF/include/footer.jsp"%> --%>
    </div>
<%@ include file="/WEB-INF/include/footer.jsp"%>
  </div>
  </div>
  <script type="text/javascript">

	$("#checkall").click(function() {
		if (this.checked) {
			$("input[name='checkbox']").each(function() {
				this.checked = true;
			});
		} else {
			$("input[name='checkbox']").each(function() {
				this.checked = false;
			});
		}
	});
  </script>	
  <script type="text/javascript">

	$("#applyBtn").click(function() {
		  var orderIds = "";
		  $('input:checkbox[name=checkbox]:checked').each(function(){

		  		orderIds += $(this).val() + ',';
		  })

		  if(orderIds.length < 2){
				alert("请勾选订单后执行！");
				event.preventDefault();
				return;
		  }

		  var remark = $("#remark").val();
		  
		  //window.location.href="${ctx}/payment/manage/doApply?orderIds="+orderIds+"&remark="+remark+"";
		  $.ajax({

			  type:'GET',
		       url:'${ctx}/payment/agency/doApply',
		       data:{'orderIds':orderIds,'remark':remark},
		       dataType: 'json',
		       error: function(){
		           alert('网络错误！稍后再试！');
		       },
		       success:function(data){
			       if(data.code == 1){
			    	   $('#errorDialog').find('.modal-body p').text(data.message).end().modal();
			       }else{
		    		   alert("申请成功！");
		    		   window.location.href = "${ctx}/payment/manage/apply";
			       }
		       }
		  });
	});
  </script>
  
  <script>
    $("#closeBtn").bind("click", function(){
      window.location.href = "${ctx}/payment/manage/apply";
    });
</script>
  
<!--      <script type="text/javascript">
  
     $("#payBtn").click(function(){
    	 alert("Q");
        $('#payBtn').attr('disabled',"true");
        $('#payBtn').html("打款中……");
        var orderId = $("#orderId").val();
        var payAmount = $("#payAmount").val();
        var isInterbank = $("#isInterbank").val();
        var accountNo = $("#accountNo").val();
        var accountName = $("#accountName").val();
        var remark = $("#remark").val();
        $.ajax({
  
          type:'POST',
             url:'${ctx}/payment/directbank/doPay',
             data:{'batchPayRecordId':batchPayRecordId,'amount':amount,'isInterbank':isInterbank,'accountNo':accountNo,'accountName':accountName,'remark':remark},
             dataType: 'json',
             error: function(){
                 $('.close').click();
                 alert('网络错误！稍后再试！');
                 $('#payBtn').removeAttr("disabled");
                 $('#payBtn').html("扣款");
             },
             success:function(data){
            	 $('.close').click();
               $('#dialog').find('.modal-body p').text(data.message).end().modal();
               
             }
        });
    }); 
  </script> -->

  <%@ include file="/WEB-INF/include/script.jsp"%>
  <script src="${ctx.resource}/js/bootstrap-switch.min.js"></script>
  <script src="${ctx.resource}/js/bootstrap-modal-trigger.js"></script>
  <script src="${ctx.resource}/js/select2.min.js"></script>
  <script src="${ctx.resource}/js/select2_locale_zh-CN.js"></script>
  <script src="${ctx.resource}/js/bootstrap.validate.js"></script>
  <script src="${ctx.resource}/js/bootstrap.validate.en.js"></script>
  <script src="${ctx.resource}/js/earth-preupload.js"></script>
  <script src="${ctx.resource}/js/bootstrap-alert-fade-trigger.js"></script>
  <div class="modal fade" id="errorDialog" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">提示</h4>
      </div>
      <div class="modal-body">
        <p></p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal" id="closeBtn">关闭</button>
      </div>
    </div>
  </div>
</div>

  <div class="modal fade" id="payDialog" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">合并打款</h4>
      </div>
      <div class="modal-body">
		
		    <form class="form-horizontal" class ="form-horizontal"  data-validate ="true">
		
			<input type="hidden" name="batchPayRecordId" value="${batchPayRecordId}" id="batchPayRecordId" >
		      <div class="modal-body">
		
		        <div class="form-group demo2do-form-group">
		
		          <label class="col-xs-2 control-label">打款金额</label>
		          <div class="col-xs-4">
		            <input type="number" step="1" min="0" required="required" class="form-control" name="amount" id="amount" value="${amount }"/>
		          </div>
		          
		          <label class="col-xs-2 control-label">是否跨行</label>
		          <div class="col-xs-4">
		            <select class="form-control" name="isInterbank" id="isInterbank">
		                <option value="0">不跨行</option>
		                <option value="1">跨行</option>
		            </select>
		          </div>
		
		        </div>
		        
		        <div class="form-group demo2do-form-group">
		        
		          <label class="col-xs-4 control-label">帐号</label>
		
		          <div class="col-xs-5">
		            <input type="text" class="form-control" name="accountNo" id="accountNo" value="${receiveAccountNo }" disabled="disabled"/>
		          </div>
		          
		          <label class="col-xs-4 control-label">户名</label>
		
		          <div class="col-xs-5">
		            <input type="text" class="form-control" name="accountName" id="accountName" value="${receiveAccountName }" disabled="disabled"/>
		          </div>
		
		        </div>
		        <div class="form-group demo2do-form-group">
		          <label class="col-xs-4 control-label">备注</label>
		
		          <div class="col-xs-5">
		            <input type="text" class="form-control" name="remark" id="remark" value="${remark }"/>
		          </div>
		        </div>
		
		      </div>
		
		      <div class="modal-footer">
		        <button type="button" class="btn btn-success btn-shadow btn-shadow-success demo2do-btn" id="payBtn" onclick="javascript:doPay();">确认打款</button>&nbsp;&nbsp;&nbsp;&nbsp;
		        <button type="button" class="btn btn-default btn-shadow btn-shadow-default demo2do-btn" data-dismiss="modal">取消</button>
		      </div>
		
		    </form>
		
      </div>
    </div>
  </div>
</div>

<div class="modal fade" id="dialog" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">提示</h4>
      </div>
      <div class="modal-body">
        <p></p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal" id="closeBtn">关闭</button>
      </div>
    </div>
  </div>
</div>

<script type="text/javascript">
  function doPay(){
   
      $('#payBtn').attr('disabled',"true");
      $('#payBtn').html("打款中……");
      var batchPayRecordId = $("#batchPayRecordId").val();
      var amount = $("#amount").val();
      var isInterbank = $("#isInterbank").val();
      var accountNo = $("#accountNo").val();
      var accountName = $("#accountName").val();
      var remark = $("#remark").val();
      $.ajax({

        type:'POST',
           url:'${ctx}/payment/directbank/doPay',
           data:{'batchPayRecordId':batchPayRecordId,'amount':amount,'isInterbank':isInterbank,'accountNo':accountNo,'accountName':accountName,'remark':remark},
           dataType: 'json',
           error: function(){
               $('.close').click();
               alert('网络错误！稍后再试！');
               $('#payBtn').removeAttr("disabled");
               $('#payBtn').html("扣款");
           },
           success:function(data){
          	 $('.close').click();
             $('#dialog').find('.modal-body p').text(data.message).end().modal();
             
           }
      });
   }
 </script>
</body>
</html>
